<template>
  <div class="demo">
    <div class="demo-title">搜索</div>
    <div class="demo-content">
      <Cascader
        v-model:value="value"
        :options="options"
        :show-search="{ filter }"
        placeholder="Please select"
      />
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import Cascader from '@sscd/cascader';
  import type { CascaderProps, ShowSearchType } from '@sscd/cascader';
  const value = ref<string[]>([]);
  const options: CascaderProps['options'] = [
    {
      value: 'zhejiang',
      label: 'Zhejiang',
      children: [
        {
          value: 'hangzhou',
          label: 'Hangzhou',
          children: [
            { value: 'xihu', label: 'West Lake' },
            { value: 'xiasha', label: 'Xia Sha', disabled: true },
          ],
        },
      ],
    },
    {
      value: 'jiangsu',
      label: 'Jiangsu',
      children: [
        {
          value: 'nanjing',
          label: 'Nanjing',
          children: [{ value: 'zhonghuamen', label: 'Zhong Hua men' }],
        },
      ],
    },
  ];
  const filter: ShowSearchType['filter'] = (inputValue, path) => {
    return path.some((option) => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
  };
</script>
